import { Cartesian3, CesiumTerrainProvider } from 'cesium';
import { isNil } from 'lodash';
import { useEffect } from 'react';
import { useCesium } from 'resium';
import { CesiumMath } from '../../../../utils/Type';

export default function Demo() {
    const { viewer } = useCesium();

    useEffect(() => {
        if (isNil(viewer)) return;
        const target = Cartesian3.fromDegrees(101.9139862, 30.1876105, 3000);
        viewer.camera.setView({
            destination: target,
            orientation: {
                heading: viewer.camera.heading,
                pitch: CesiumMath.toDegrees(0),
                roll: viewer.camera.roll,
                up: Cartesian3.clone(Cartesian3.UNIT_Y),
            },
        });
        CesiumTerrainProvider.fromUrl('http://www.freexgis.com/web-data/terrain').then(
            (terrainProvider) => {
                viewer.scene.globe.terrainProvider = terrainProvider;
            }
        );
    }, [viewer]);

    return null;
}
